<?php

namespace app\Controllers;
use app\Models\UserModel as Customer;

class CustomerController {

	//抽取CustomerModel对象父类
	protected $model;

	public function __construct() {
		$this -> model = new Customer();
	}

	public function searchCustomer() {
		$result = $this -> model -> searchCustomerModel();
		echo json_encode($result);
	}

	public function deleteCustomer($request, $response) {
		$id = $request -> getParam("id");
		$result = $this -> model -> deleteCustomerModel($id);
		echo json_encode($result);
	}

	public function modifyCustomer($request, $response) {
		$customer_id = $request -> getParam("customer_id");
		$customer_name = $request -> getParam("customer_name");
		$contact_name = $request -> getParam("contact_name");
		$phone = $request -> getParam("phone");
		$address = $request -> getParam("address");
		$province = $request -> getParam("province");
		$city = $request -> getParam("city");
		$sale_employee_id = $request -> getParam("sale_employee_id");
		$credit_limit = $request -> getParam("credit_limit");
		$customer = Array();
		$customer["customer_id"] = $customer_id;
		$customer["customer_name"] = $customer_name;
		$customer["contact_name"] = $contact_name;
		$customer["phone"] = $phone;
		$customer["address"] = $address;
		$customer["province"] = $province;
		$customer["city"] = $city;
		$customer["sale_employee_id"] = $sale_employee_id;
		$customer["credit_limit"] = $credit_limit;
		$result = $this -> model -> modifyCustomerModel($customer);
		echo json_encode($result);
	}

	public function insertCustomer($request, $response) {
		$customer_name = $request -> getParam("customer_name");
		$contact_name = $request -> getParam("contact_name");
		$phone = $request -> getParam("phone");
		$address = $request -> getParam("address");
		$province = $request -> getParam("province");
		$city = $request -> getParam("city");
		$sale_employee_id = $request -> getParam("sale_employee_id");
		$credit_limit = $request -> getParam("credit_limit");
		$customer = Array();
		$customer["customer_name"] = $customer_name;
		$customer["contact_name"] = $contact_name;
		$customer["phone"] = $phone;
		$customer["address"] = $address;
		$customer["province"] = $province;
		$customer["city"] = $city;
		$customer["sale_employee_id"] = $sale_employee_id;
		$customer["credit_limit"] = $credit_limit;
		$result = $this -> model -> insertCustomerModel($customer);
		echo json_encode($result);
	}

}
?>